package com.aos.erp.gov.ex.web.rest;

import com.alibaba.druid.support.json.JSONUtils;
import com.aos.erp.common.bean.PageBean;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.gov.ex.model.GovSchoolTicket;
import com.aos.erp.gov.ex.service.GovSchoolTicketService;
import com.aos.erp.gov.ex.task.mq.HelloSender;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


@Slf4j
@RestController("SchoolTicketController")
@RequestMapping("/api/ex/school/ticket")
@Api("SchoolTicketController")
public class GovSchoolTicketController {

    @Resource
    private HelloSender sender;
    @Resource
    private GovSchoolTicketService schoolTicketService;

    @GetMapping("/list")
    @ApiOperation(value = "分页查询")
    public ResultEntity<PageBean<GovSchoolTicket>> queryPageBean(@RequestParam(name = "pageIndex", required = false, defaultValue = "1") int pageIndex
            , @RequestParam(name = "pageSize", required = false, defaultValue = "20") int pageSize) {
        return ResultEntity.success(schoolTicketService.queryByPage(pageIndex, pageSize));
    }

    @PostMapping("/saveCookies")
    @ApiOperation(value = "保存cookies")
    public ResultEntity saveCookies(@RequestBody Map<String,String> params) {
        log.info("收到登录信息：" + JSONUtils.toJSONString(params));
        String webCode = params.get("webCode");
        webCode = webCode.replace("https://", "");
        webCode = webCode.replace("http://", "");
        String account = params.get("account");
        String deviceId = params.get("deviceId");
        String cookie = params.get("cookie");
        schoolTicketService.saveCookies(webCode, account, deviceId, cookie);
        return ResultEntity.success();
    }

    @GetMapping("/send")
    public ResultEntity send() {
        sender.send();
        return ResultEntity.success();
    }

}